package com.oj.system.controller.exam;

import com.oj.common.core.constants.HttpConstants;
import com.oj.common.core.controller.BaseController;
import com.oj.common.core.domain.R;
import com.oj.common.core.domain.TableDataInfo;
import com.oj.system.domain.exam.dto.*;
import com.oj.system.domain.exam.vo.ExamDetailVO;
import com.oj.system.service.exam.impl.ExamServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author bin
 * @Date 2025/5/6
 */

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private ExamServiceImpl examService;


    @GetMapping("/list")
    @Operation(summary = "竞赛列表", description = "根据查询条件筛选查询竞赛列表")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public TableDataInfo list(ExamQueryDTO examQueryDTO, @RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        //这个分页的list使用写xml的方式进行查询 不在像QuestionServiceImpl那样使用mybatisPlus进行查询
        return examService.list(examQueryDTO,token);
    }

    @PostMapping("/add")
    @Operation(summary = "竞赛新增", description = "根据内容新增竞赛")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<String> add(@RequestBody @Validated  ExamSaveDTO examSaveDTO) {
        return examService.add(examSaveDTO);
    }



    @PostMapping("/question/add")
    @Operation(summary = "带有题目的竞赛新增", description = "根据题目Ids竞赛Id新增竞赛")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<Void> questionAdd(@RequestBody  ExamQuestSaveDTO examQuestSaveDTO) {
        return toR(examService.questionAdd(examQuestSaveDTO));
    }

    @GetMapping("/detail")
    @Operation(summary = "根据题竞赛Id查询竞赛detail", description = "根据题竞赛Id查询竞赛detail")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<ExamDetailVO> detail(Long examId) {
        return examService.detail(examId);
    }

    @PutMapping("/edit")
    @Operation(summary = "竞赛基本信息编辑", description = "根据题竞赛Id和更新信息更新exam")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<Void> edit(@RequestBody  @Validated ExamEditDTO examEditDTO) {
        return toR(examService.edit(examEditDTO));
    }

    @DeleteMapping("/question/delete")
    @Operation(summary = "竞赛中题目信息的删除", description = "竞赛中题目信息的删除")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<Void> questionDelete(Long examId, Long questionId) {
        return toR(examService.questionDelete(examId, questionId));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "竞赛删除", description = "根据竞赛id新增竞赛")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<Void> delete(Long examId) {
        return toR(examService.delete(examId));
    }

    @PutMapping("/publish")
    @Operation(summary = "竞赛发布", description = "满足竞赛发布的前提下 根据竞赛id发布竞赛")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<Void> publish(Long examId) {
        return toR(examService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    @Operation(summary = "竞赛撤销发布", description = "根据竞赛id撤销发布竞赛")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    public R<Void> cancelPublish(Long examId) {
        return toR(examService.cancelPublish(examId));
    }

}